import { Vector3, BufferGeometry, Vector2, BufferAttribute } from "three"
import { Point } from "../../Docs"

export default class GeometryUtil {
    /**
      * 顺时针排序顶点
      * @param points 
      */
    public static sortClockwise(points) {
        points.sort((a, b) => a.y - b.y)
        const cy = (points[0].y + points[points.length - 1].y) / 2

        points.sort((a, b) => b.x - a.x)
        const cx = (points[0].x + points[points.length - 1].x) / 2

        const center = { x: cx, y: cy }

        // Pre calculate the angles as it will be slow in the sort
        // As the points are sorted from right to left the first point
        // is the rightmost

        // Starting angle used to reference other angles
        var startAng
        points.forEach((point) => {
            var ang = Math.atan2(point.y - center.y, point.x - center.x)
            if (!startAng) { startAng = ang } else {
                if (ang < startAng) { // ensure that all points are clockwise of the start point
                    ang += Math.PI * 2
                }
            }
            point.angle = ang // add the angle to the point
        })

        // Sort clockwise;
        points.sort((a, b) => a.angle - b.angle)
    }
    /**
     * 计算三角形面积
     * @static
     * @param {Vec3} p0 - 三角形顶点1
     * @param {Vec3} p1 - 三角形顶点2
     * @param {Vec3} p2 - 三角形顶点3
    */
    public static Area(p0, p1, p2) {
        var area = 0.0
        area = p0.x * p1.y + p1.x * p2.y + p2.x * p0.y - p1.x * p0.y - p2.x * p1.y - p0.x * p2.y
        return area / 2
    }

    /**
    * 计算重心
    * @static
    * @param {Array} points - 点位数据，但要求经纬度的属性为x和y
    * @memberof ComputeUtil
    */
    public static getPolygonAreaCenter(points) {
        var sumx = 0
        var sumy = 0
        var sumArea = 0
        var p1 = points[1]
        for (var i = 2; i < points.length; i++) {
            var p2 = points[i]
            var area = this.Area(points[0], p1, p2)
            sumArea += area
            sumx += (points[0].x + p1.x + p2.x) * area
            sumy += (points[0].y + p1.y + p2.y) * area
            p1 = p2
        }
        var xx = sumx / sumArea / 3
        var yy = sumy / sumArea / 3
        return {
            x: xx,
            y: yy
        }
    }

    // /**
    //  * 用耳切法计算三角形顶点数组
    //  * @param points 顶点数组
    //  * @param isGetTexCoord 是否计算纹理坐标
    //  * @returns 
    //  */
    // public static earClipping2D(points: Array<Point>, isGetTexCoord: boolean): { pointArray: Array<number>, uvCoordArray: Array<number>, isCCW: boolean, width: number, height: number, minX: number, minY: number, firstPoint: Vector3 } {
    //     let bPolygonIsConvex: Array<boolean> = new Array<boolean>();//对所有polygon点信息，凹凸信息进行标定 
    //     let finalNormal: Vector3 = new Vector3();
    //     let finalDirection = 0;
    //     finalNormal.x = 0;
    //     finalNormal.y = 0;
    //     finalNormal.z = 0;

    //     for (let i = 0; i < points.length; ++i) {//判断顶点是顺时针还是逆时针
    //         let curPos: Vector3 = points[i].toEPSGWeb(); //new Vector3(points[i][0], points[i][1], 0);
    //         let leftPos: Vector3;
    //         let rightPos: Vector3;

    //         if (i == 0) {
    //             let iEnd = points.length;
    //             leftPos = points[iEnd - 1].toEPSGWeb(); //new Vector3(points.at(iEnd-1)[0], points.at(iEnd-1)[1], 0);
    //         } else {
    //             leftPos = points[i - 1].toEPSGWeb(); //new Vector3(points[i - 1][0], points[i - 1][1], 0);
    //         }

    //         if (i == (points.length - 1)) {
    //             rightPos = points[0].toEPSGWeb(); //new Vector3(points.at(0)[0], points.at(0)[1], 0);
    //         } else {
    //             rightPos = points[i + 1].toEPSGWeb(); //new Vector3(points[i + 1][0], points[i + 1][1], 0);
    //         }

    //         let tempOne: Vector3 = curPos.clone().sub(leftPos);
    //         let vectorOne: Vector3 = new Vector3();
    //         vectorOne.x = tempOne.x;
    //         vectorOne.y = tempOne.y;
    //         vectorOne.z = 0;

    //         let tempTwo = rightPos.clone().sub(curPos);
    //         let vectorTwo: Vector3 = new Vector3();
    //         vectorTwo.x = tempTwo.x;
    //         vectorTwo.y = tempTwo.y;
    //         vectorTwo.z = 0;

    //         //向量叉乘
    //         let currentNormal: Vector3 = vectorOne.cross(vectorTwo).normalize();
    //         if (currentNormal.z > 0) {
    //             finalDirection += 1;
    //             bPolygonIsConvex.push(true);
    //         } else if (currentNormal.z < 0) {
    //             finalDirection -= 1;
    //             bPolygonIsConvex.push(false);
    //         } else if (currentNormal.z == 0) {
    //             bPolygonIsConvex.push(false);
    //         }
    //     }

    //     let isCCW = (finalDirection > 0) ? true : false;
    //     let returnData: { pointArray: Array<number>, uvCoordArray: Array<number>, isCCW: boolean, width: number, height: number, minX: number, minY: number, firstPoint: Vector3 } =
    //         { pointArray: null, uvCoordArray: null, isCCW: isCCW, width: 0, height: 0, minX: 0, minY: 0, firstPoint: null };
    //     let pointArray = new Array<number>();
    //     let minX, minY, maxX, maxY;
    //     let firstPoint: Vector3;
    //     // let triangles: Array<Vector3> = new Array<Vector3>();
    //     if (points.length < 3) {
    //         return returnData;
    //     } else {
    //         let earFound = true;
    //         let lastSize = 0;
    //         while ((points.length >= 3)) {
    //             if ((points.length == lastSize)) {
    //                 finalDirection = finalDirection * -1;
    //             }
    //             lastSize = points.length;
    //             if (!earFound) {
    //                 return returnData;
    //             }

    //             for (let i = 0; i < points.length; i++) {
    //                 let curPos: Vector3 = points[i]; //new Point(points[i][0], points[i][1], 0, '3857').toEPSGWeb();
    //                 let leftPos: Vector3;
    //                 let rightPos: Vector3;
    //                 if (i == 0) {
    //                     let iEnd = points.length;
    //                     leftPos = points[iEnd - 1]; //new Point(points.at(iEnd-1)[0], points.at(iEnd-1)[1], 0, '3857').toEPSGWeb();
    //                 } else {
    //                     leftPos = points[i - 1]; //new Point(points[i - 1][0], points[i - 1][1], 0, '3857').toEPSGWeb();
    //                 }
    //                 if (i == points.length - 1) {
    //                     rightPos = points[0]; //new Point(points.at(0)[0], points.at(0)[1], 0, '3857').toEPSGWeb();
    //                 } else {
    //                     rightPos = points[i + 1]; //new Point(points[i + 1][0], points[i + 1][1], 0, '3857').toEPSGWeb();
    //                 }

    //                 let isEar = true;
    //                 let isConvex = true;

    //                 let tempOne = curPos.clone().sub(leftPos);
    //                 let vectorOne: Vector3 = new Vector3();
    //                 vectorOne.x = tempOne.x;
    //                 vectorOne.y = tempOne.y;
    //                 vectorOne.z = 0;

    //                 let tempTwo = rightPos.clone().sub(curPos);
    //                 let vectorTwo: Vector3 = new Vector3();
    //                 vectorTwo.x = tempTwo.x;
    //                 vectorTwo.y = tempTwo.y;
    //                 vectorTwo.z = 0;

    //                 let currentNormal = vectorOne.cross(vectorTwo);
    //                 currentNormal = currentNormal.normalize();

    //                 if (finalDirection > 0) { //逆时针 
    //                     if (currentNormal.z < 0) {
    //                         //法线往下，就说明这是一个凹点
    //                         isConvex = false;
    //                     }
    //                 }
    //                 else if (finalDirection < 0) { //顺时针
    //                     if (currentNormal.z > 0) {
    //                         //法线往上，就说明这是一个凹点
    //                         isConvex = false;
    //                     }
    //                 }

    //                 if (isConvex == true) {
    //                     let lastNormal: Vector3;
    //                     let currentTriangle: Array<Vector3> = new Array<Vector3>();//当前的三角形
    //                     currentTriangle.push(leftPos);
    //                     currentTriangle.push(curPos);
    //                     currentTriangle.push(rightPos);
    //                     currentTriangle.push(leftPos);

    //                     for (let j = 0; j < points.length; j++) {
    //                         if (!isEar) {
    //                             break;
    //                         }

    //                         //let currPoint:Vector3 = new Vector3(points[j][0], points[j][1], 0);
    //                         let currPoint: Vector3 = new Vector3(points[j].x, points[j].y, 0);
    //                         let isCheck = true;
    //                         for (let m = 0; m < currentTriangle.length; m++) {
    //                             let currTriganglePoint: Vector3 = currentTriangle[m];
    //                             let tempOne = currPoint.clone().sub(currTriganglePoint);
    //                             if (tempOne.x == 0 && tempOne.y == 0) {
    //                                 isCheck = false;
    //                                 break;
    //                             }
    //                         }

    //                         if (isCheck == true) {
    //                             let sum = 1;
    //                             let hasNormal = false;
    //                             for (let k = 0; k < currentTriangle.length - 1; k++) {
    //                                 let currTriganglePoint: Vector3 = currentTriangle[k];
    //                                 let nextTriganglePoint: Vector3 = currentTriangle[k + 1];

    //                                 let tempOne: Vector3 = currPoint.clone().sub(currTriganglePoint);
    //                                 let vectorOne: Vector3 = new Vector3();
    //                                 vectorOne.x = tempOne.x;
    //                                 vectorOne.y = tempOne.y;
    //                                 vectorOne.z = 0;

    //                                 let tempTwo: Vector3 = nextTriganglePoint.clone().sub(currTriganglePoint);
    //                                 let vectorTwo: Vector3 = new Vector3();
    //                                 vectorTwo.x = tempTwo.x;
    //                                 vectorTwo.y = tempTwo.y;
    //                                 vectorTwo.z = 0;

    //                                 let currentNormal: Vector3 = vectorOne.cross(vectorTwo);
    //                                 if (hasNormal) {
    //                                     let direct = lastNormal.z * currentNormal.z;
    //                                     if (direct > 0) {
    //                                         sum++;
    //                                     } else {
    //                                         sum--;
    //                                     }
    //                                 }
    //                                 hasNormal = true;
    //                                 lastNormal = currentNormal;
    //                             }

    //                             if (sum < 3) { //没有被三角形包含
    //                                 isEar = true;
    //                             } else if (sum >= 3) {//被三角形包含
    //                                 isEar = false;
    //                                 break;
    //                             }
    //                         }
    //                     }
    //                 } else {
    //                     isEar = false;
    //                     if (points.length == 3) {
    //                         earFound = false;
    //                     }
    //                 }

    //                 if (isEar && points.length >= 3) {
    //                     let currentMinX = Math.min(leftPos.x, curPos.x, rightPos.x);
    //                     let currentMinY = Math.min(leftPos.y, curPos.y, rightPos.y);
    //                     let currentMaxX = Math.max(leftPos.x, curPos.x, rightPos.x);
    //                     let currentMaxY = Math.max(leftPos.y, curPos.y, rightPos.y);

    //                     if (pointArray.length == 0) {
    //                         minX = currentMinX;
    //                         minY = currentMinY;
    //                         maxX = currentMaxX;
    //                         maxY = currentMaxY;

    //                         firstPoint = leftPos.clone();
    //                     } else {
    //                         if (currentMinX < minX) {
    //                             minX = currentMinX;
    //                         }
    //                         if (currentMinY < minY) {
    //                             minY = currentMinY;
    //                         }
    //                         if (currentMaxX > maxX) {
    //                             maxX = currentMaxX;
    //                         }
    //                         if (currentMaxY > maxY) {
    //                             maxY = currentMaxY;
    //                         }
    //                     }

    //                     pointArray.push(leftPos.x - firstPoint.x, leftPos.y - firstPoint.y, leftPos.z - firstPoint.z);
    //                     pointArray.push(curPos.x - firstPoint.x, curPos.y - firstPoint.y, curPos.z - firstPoint.z);
    //                     pointArray.push(rightPos.x - firstPoint.x, rightPos.y - firstPoint.y, rightPos.z - firstPoint.z);

    //                     let bufferArray: Array<Point> = new Array<Point>();
    //                     for (let n = 0; n < points.length; n++) { //把数组复制到新的数组中，为了不破坏原始数据
    //                         if (n != i) {
    //                             bufferArray.push(points[n]);
    //                         }
    //                     }
    //                     points = bufferArray;
    //                     i = i - 1;
    //                 }
    //             }
    //         }
    //     }

    //     returnData.width = maxX - minX;
    //     returnData.height = maxY - minY;
    //     returnData.minX = minX;
    //     returnData.minY = minY;
    //     returnData.pointArray = pointArray;
    //     returnData.firstPoint = firstPoint;

    //     let uvCoordArray = [];
    //     if (isGetTexCoord) {
    //         for (let i = 0; i < pointArray.length; i += 3) {
    //             let u = ((pointArray[i] + firstPoint.x) - minX) / returnData.width;
    //             let v = ((pointArray[i + 1] + firstPoint.y) - minY) / returnData.height;
    //             uvCoordArray.push(u);
    //             uvCoordArray.push(v);
    //         }
    //     }
    //     returnData.uvCoordArray = uvCoordArray;

    //     return returnData;
    // }


    // /**根据经纬度坐标数组，高度，和中心点坐标创建墙体几何体
    //  * 创建不带顶盖的几何体
    //  * @param lnglatArray 底面顶点坐标数组
    //  * @param height 几何体高度
    //  * @param centerLnglat 基准点坐标，大坐标防抖动处理，一般传lnglatArray中第一个点坐标
    //  */
    // public static generateWallGeometry(lnglatArray: Array<Point>, height: number, centerLnglat: Point): BufferGeometry {
    //     let pointArray = new Array<Vector3>();
    //     let centerPosition = centerLnglat.toEPSGWeb().clone();

    //     let pointVector: Point;
    //     lnglatArray.forEach(element => {
    //         let currentPoint = new Point(element.x, element.y, element.z, element.EPSGType);
    //         pointVector = currentPoint.toEPSGWeb();
    //         pointArray.push(pointVector.sub(centerPosition));
    //     });

    //     if (!pointArray[0].equals(pointArray[pointArray.length - 1])) {
    //         pointArray.push(pointArray[0]);
    //     }

    //     let totalDistance = 0;
    //     for (let i = 1; i < pointArray.length; i++) {
    //         let previousPoint = pointArray[i - 1];
    //         let point = pointArray[i];
    //         totalDistance += point.distanceTo(previousPoint);

    //         previousPoint = point;
    //     }

    //     let geometry = new BufferGeometry();
    //     let verticeArray = []; //geometry.vertices;
    //     let faceArray = []; //geometry.faces;
    //     let texcoordArray = [];//geometry.faceVertexUvs[0];
    //     let index = 0;
    //     let length = pointArray.length;
    //     let textureBottom = 0;
    //     let textureTop = 1;
    //     if (height < 0) { //墙体的高度小于0，纹理的采样要从下到上
    //         textureBottom = 1;
    //         textureTop = 0;
    //     }
    //     let i = 1;
    //     let currentIndex = 0;
    //     let previousIndex = 0;
    //     let currentDistance = 0;
    //     let isOver = false;
    //     for (i = 1; i < length; i++) {
    //         if (isOver == true) {
    //             break;
    //         }

    //         if (i == 1) {
    //             currentIndex = i;
    //             if (currentIndex >= length - 1) {
    //                 return null;
    //             }
    //         } else {
    //             currentIndex = previousIndex + 1;
    //         }

    //         if (currentIndex > length - 1) {
    //             currentIndex = length - 1;
    //             isOver = true;
    //         }

    //         let firstPoint = pointArray[previousIndex];
    //         verticeArray.push(firstPoint.x, firstPoint.y, firstPoint.z);

    //         let secondPoint = pointArray[currentIndex];
    //         verticeArray.push(secondPoint.x, secondPoint.y, secondPoint.z);

    //         let thirdCoord = new Vector3(pointArray[currentIndex].x, pointArray[currentIndex].y, pointArray[currentIndex].z + height);
    //         verticeArray.push(thirdCoord.x, thirdCoord.y, thirdCoord.z);

    //         let fourCoord = new Vector3(pointArray[previousIndex].x, pointArray[previousIndex].y,
    //             pointArray[previousIndex].z + height);
    //         verticeArray.push(fourCoord.x, fourCoord.y, fourCoord.z);

    //         index = index + 4;
    //         previousIndex = currentIndex;

    //         //一个三角形
    //         faceArray.push(index - 4, index - 3, index - 2);

    //         //一个三角形
    //         faceArray.push(index - 4, index - 2, index - 1);

    //         let pieceDistance = firstPoint.distanceTo(secondPoint);
    //         currentDistance += pieceDistance;

    //         let firstPointPercent = (currentDistance - pieceDistance) / totalDistance;
    //         let secondPointPercent = currentDistance / totalDistance

    //         let firstPointUV = new Vector2(firstPointPercent, textureBottom);
    //         texcoordArray.push(firstPointUV.x, firstPointUV.y);
    //         let secondPointUV = new Vector2(secondPointPercent, textureBottom);
    //         texcoordArray.push(secondPointUV.x, secondPointUV.y);
    //         let threePointUV = new Vector2(secondPointPercent, textureTop);
    //         texcoordArray.push(threePointUV.x, threePointUV.y);

    //         let fourPointUV = new Vector2(firstPointPercent, textureTop);
    //         texcoordArray.push(fourPointUV.x, fourPointUV.y);

    //     }
    //     geometry.setIndex(faceArray);
    //     geometry.setAttribute('position', new BufferAttribute(new Float32Array(verticeArray), 3));

    //     geometry.setAttribute('uv', new BufferAttribute(new Float32Array(texcoordArray), 2));
    //     geometry.computeVertexNormals();
    //     // geometry.computeVertexNormals();
    //     // material.side = FrontSide; //DoubleSide; // BackSide FrontSide
    //     // material.shininess = 1;

    //     // let buffGeom = new BufferGeometry();
    //     // buffGeom.fromGeometry(geometry);
    //     geometry['pointArray'] = pointArray;
    //     return geometry;
    // }


    /**
    * 判断点在线段上
    * @param px0 点信息
    * @param py0 点信息
    * @param px1 线的起始点信息
    * @param py1 线的起始点信息
    * @param px2 线的结束点信息
    * @param py2 线的结束点信息
    */
    public static IsPointOnLine(px0: any, py0: any, px1: any, py1: any, px2: any, py2: any): boolean {
        let EPSILON = 0.000001;
        let flag = false;
        let d1 = (px1 - px0) * (py2 - py0) - (px2 - px0) * (py1 - py0);
        if ((Math.abs(d1) < EPSILON) && ((px0 - px1) * (px0 - px2) <= 0) && ((py0 - py1) * (py0 - py2) <= 0)) {
            flag = true;
        }
        return flag;
    }

    /**
    * 判断两线段相交
    */
    public static IsIntersect(px1: any, py1: any, px2: any, py2: any, px3: any, py3: any, px4: any, py4: any): boolean {
        let flag = false;
        let d = (px2 - px1) * (py4 - py3) - (py2 - py1) * (px4 - px3);
        if (d != 0) {
            let r = ((py1 - py3) * (px4 - px3) - (px1 - px3) * (py4 - py3)) / d;
            let s = ((py1 - py3) * (px2 - px1) - (px1 - px3) * (py2 - py1)) / d;
            if ((r >= 0) && (r <= 1) && (s >= 0) && (s <= 1)) {
                flag = true;
            }
        }
        return flag;
    }

    /**
    * 检测一个点是否在一个由多个点组成的多边形中
    * @param pointVector 点信息
    * @param polygon 多边形信息
    */
    public static isInShape(pointVector: Vector3 | Vector2, polygon: Array<Vector3 | Vector2>): boolean {
        let EPSILON = 0.000001;
        let isInside = false;
        let count = 0;
        let DBL_MAX = 1.7976931348623158e+308;
        let x = pointVector.x;
        let y = pointVector.y;

        //首尾不相连的情况
        let length = polygon.length;
        if ((Math.abs(polygon[0].x - polygon[length - 1].x) > EPSILON) || Math.abs(polygon[0].y - polygon[length - 1].y) > EPSILON) {
            polygon.push(polygon[0]);
        }

        //
        let minX = DBL_MAX;
        for (let i = 0; i < polygon.length; i++) {
            minX = Math.min(minX, polygon[i].x);
        }
        //
        let px = x;
        let py = y;
        let linePoint1x = x;
        let linePoint1y = y;
        let linePoint2x = minX - 10;			//取最小的X值还小的值作为射线的终点
        let linePoint2y = y;

        //遍历每一条边
        for (let i = 0; i < polygon.length - 1; i++) {
            let cx1 = polygon[i].x;
            let cy1 = polygon[i].y;
            let cx2 = polygon[i + 1].x;
            let cy2 = polygon[i + 1].y;

            if (this.IsPointOnLine(px, py, cx1, cy1, cx2, cy2)) {
                return true;
            }

            if (Math.abs(cy2 - cy1) < EPSILON)   //平行则不相交
            {
                continue;
            }

            if (this.IsPointOnLine(cx1, cy1, linePoint1x, linePoint1y, linePoint2x, linePoint2y)) {
                if (cy1 > cy2)			//只保证上端点+1
                {
                    count++;
                }
            }
            else if (this.IsPointOnLine(cx2, cy2, linePoint1x, linePoint1y, linePoint2x, linePoint2y)) {
                if (cy2 > cy1)			//只保证上端点+1
                {
                    count++;
                }
            }
            else if (this.IsIntersect(cx1, cy1, cx2, cy2, linePoint1x, linePoint1y, linePoint2x, linePoint2y))   //已经排除平行的情况
            {
                count++;
            }
        }

        if (count % 2 == 1) {
            isInside = true;
        }

        return isInside;
    }

    /**
    * 计算出cos、sin值
    * @param startPoint 起始点
    * @param endPoint 结束点
    */
    public static computeCosSin(startPoint: Vector3, endPoint: Vector3) {
        let distance = startPoint.distanceTo(endPoint);
        let xDistance = Math.abs(startPoint.x - endPoint.x);
        let yDistance = Math.abs(startPoint.y - endPoint.y);
        let cosValue = (xDistance / distance);
        let sinValue = (yDistance / distance);
        return { cos: cosValue, sin: sinValue };
    }

    /**
    * 从startPoint到endPoint的线段，将startPoint往相反的方向扩展一段距离，距离为distance
    * @param startPoint 起始点
    * @param endPoint 结束点
    * @param distance 长度信息
    * @param angleMsg 角度信息
    */
    public static getNewPoint(startPoint: Vector3, endPoint: Vector3, distance: number, angleMsg: any) {
        let newPoint = startPoint.clone();
        let xDistance = angleMsg.cos * distance;
        let yDistance = angleMsg.sin * distance;

        if (startPoint.x < endPoint.x) {
            newPoint.x -= xDistance;
        } else if (startPoint.x > endPoint.x) {
            newPoint.x += xDistance;
        }

        if (startPoint.y < endPoint.y) {
            newPoint.y -= yDistance;
        } else if (startPoint.y > endPoint.y) {
            newPoint.y += yDistance;
        }

        return newPoint;
    }

    /**
     * 判断一个点是否在多边形内
     * @param point 点对象
     * @param pointArray 多边形数组
     * @returns true表示在点在多边形内，false表示在多边形外
     */
    public static isInPolygon(point: Point, pointArray: Array<Point>): boolean {
        let isFirst = true;
        let lastNormal = new Vector3(0.0, 0.0, 0.0);
        point.toEPSGWeb();

        let isContain = true;
        for (let i = 0; i < pointArray.length; i++) {
            let currentPoint = pointArray[i].toEPSGWeb(); 
            let nextPoint
            if(i == pointArray.length - 1) { //最后一个点，nextPoint为第一个点
                nextPoint = pointArray[0].toEPSGWeb(); 
            }else{
                nextPoint = pointArray[i + 1].toEPSGWeb(); 
            }
            

            let currentToNextVec = new Vector3(nextPoint.x - currentPoint.x, nextPoint.y - currentPoint.y, 0.0);
            if (currentToNextVec.length() == 0.0) {
                continue;
            }
            let pointToCurrentVec = new Vector3(point.x - currentPoint.x, point.y - currentPoint.y, 0.0);
            let normal = currentToNextVec.cross(pointToCurrentVec);

            if (isFirst == true) {
                isFirst = false;
            } else {
                let dirct = lastNormal.z * normal.z;
                if (dirct < 0.0) {
                    isContain = false;
                    break;
                }
            }
            lastNormal = new Vector3(normal.x, normal.y, normal.z);
        }

        return isContain;
    }
}